package com.jzy.message.activities.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jzy.message.R;
import com.jzy.message.activities.base.AppConfig;
import com.jzy.message.activities.base.AppRequestInterface;
import com.jzy.message.activities.base.BaseCommonAdapter;
import com.jzy.message.util.image.ImageConfig;

import org.xutils.common.Callback;
import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/7/2.
 */
public class MessageMeAdapter<T> extends BaseCommonAdapter {
    public MessageMeAdapter(Context context, int layout_resource_id, List<T> adapter_data, int max_item_count)
    {
        super(context,layout_resource_id,adapter_data,max_item_count);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        RelativeLayout list_item_layout = (RelativeLayout) LayoutInflater.from(context).inflate(layout_resource_id, null);
        Map<String, Object> map = (Map<String, Object>)adapter_data.get(position);
        String sImgUrl_ReplyUserAvatarImage = AppConfig.JsonUrl + map.get("replyUserAvatarImage").toString();
        String sCommentMessageType=map.get("commentMessageType").toString();
        String sImage128Id=map.get("image128Id").toString();
        final String sAuthorUserId=map.get("authorUserId").toString();
        String sImg128Url= AppConfig.sPic_Video_ServerIP + map.get("thumbnail").toString();//AppRequestInterface.getImg128Url(sImage128Id,sAuthorUserId);
        String sReplyContext=map.get("replyContext").toString();
        final ImageView cv_message_me_replyuseravatarimage=(ImageView)list_item_layout.findViewById(R.id.cv_message_me_replyuseravatarimage);
        cv_message_me_replyuseravatarimage.setImageResource(R.drawable.temp_picpeople);
        x.image().loadDrawable(sImgUrl_ReplyUserAvatarImage, ImageConfig.image_options_default, new Callback.CommonCallback<Drawable>() {
            @Override
            public void onSuccess(Drawable drawable) {
                cv_message_me_replyuseravatarimage.setImageDrawable(drawable);
            }

            @Override
            public void onError(Throwable throwable, boolean b) {

            }

            @Override
            public void onCancelled(CancelledException e) {

            }

            @Override
            public void onFinished() {

            }
        });
        cv_message_me_replyuseravatarimage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                /*context.startActivity(new Intent(context, HomeUserProfileActivity.class)
                        .putExtra("Paras", new String[]{sAuthorUserId}));*/
            }
        });
        TextView tv_message_me_replycontext=(TextView)list_item_layout.findViewById(R.id.tv_message_me_replycontext);
        tv_message_me_replycontext.setText(sReplyContext);
        ImageView iv_message_me_image128=(ImageView)list_item_layout.findViewById(R.id.iv_message_me_image128);
        x.image().bind(iv_message_me_image128, sImg128Url, ImageConfig.image_options_default);
        return list_item_layout;
    }
}
